package name.jiaosha.air.user.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import name.jiaosha.air.user.dao.IUserDao;
import name.jiaosha.air.user.domain.LoginUser;
import name.jiaosha.air.user.service.IUserService;

@Service
@Transactional
public class UserService implements IUserService {
	@Autowired
	private IUserDao userDao;
	
	

	@Override
	public LoginUser getLoginUserById(Integer id) {
		
		return userDao.get(id);
	}

	@Override
	public LoginUser getLoginUserByQQ(String qq) {

		String jpql = "SELECT u FROM LoginUser u WHERE u.qq=?1";
		return userDao.findForObject(jpql, qq);

	}

	@Override
	public void updatePassWord(String qq, String oldPassword, String newPassWord) {

	}

	@Override
	public void createLoginUser(LoginUser loginUser) {

		userDao.save(loginUser);
	}

	@Override
	public LoginUser updateLoginUser(LoginUser loginUser) {

		return userDao.saveOrUpdate(loginUser);
	}

	@Override
	public List<LoginUser> getLoginUserListByComId(Integer comId) {
		String jpql = "SELECT u FROM LoginUser u WHERE u.company.id=?1";
		return userDao.find(jpql, comId);
	}

}
